//
//  SetStaffFloorTimeCell.m
//  QRMaster
//
//  Created by myApple on 16/5/20.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "SetStaffFloorTimeCell.h"

@interface SetStaffFloorTimeCell()

@property(nonatomic,strong)UIImageView * floorImgView;

@property(nonatomic,strong)UILabel * floorNameLabel;

@property(nonatomic,strong)UILabel * buildingNameLabel;

//@property(nonatomic,strong)UILabel * roomTotalLabel;

@property(nonatomic,strong)AssignFloorTimeModel * InfoModel;

@end

@implementation SetStaffFloorTimeCell

#pragma mark -------init
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * cellId = @"GroupTableViewCell";
    SetStaffFloorTimeCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[SetStaffFloorTimeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self addAllSubView];
    }
    return self;
}

-(void)addAllSubView
{
    [self addSubview:self.floorImgView];
    [self addSubview:self.floorNameLabel];
    [self addSubview:self.buildingNameLabel];
//    [self addSubview:self.roomTotalLabel];
}

#pragma mark ---------initData
-(void)setData:(AssignFloorTimeModel *)itemInfo
{
    self.InfoModel = itemInfo;
    self.buildingNameLabel.text = self.InfoModel.bulidingName;
    self.floorNameLabel.text = self.InfoModel.floorName;
//    self.roomTotalLabel.text = [NSString stringWithFormat:@"共%d间",self.InfoModel.totalRoom];
}


#pragma mark ----------layout
-(void)layoutSubviews
{
    [super layoutSubviews];
    float x = 16;
    float y = (self.frame.size.height - 39)/2.0;
    float width = 39;
    float height = 39;
    self.floorImgView.frame = CGRectMake(x, y, width, height);
    
    x += width + 10;
    y = 6;
    width = [self calculateWidth:(self.frame.size.width - x - 32 - 80) string:self.floorNameLabel.text Font:16.0];
    height = 20;
    self.floorNameLabel.frame = CGRectMake(x, y, width, height);
    
//    x += width + 10;
//    width = 100;
//    self.roomTotalLabel.frame = CGRectMake(x, y, width, height);
    
    //楼栋
    y = self.floorNameLabel.frame.size.height + self.floorNameLabel.frame.origin.y + 4;
    x = self.floorNameLabel.frame.origin.x;
    width = [self calculateWidth:(self.frame.size.width - x - 32) string:self.InfoModel.bulidingName Font:15.0];
    self.buildingNameLabel.frame = CGRectMake(x, y, width, height);
    
}

#pragma mark -----------lazy
-(UILabel *)floorNameLabel
{
    if (!_floorNameLabel) {
        _floorNameLabel = [[UILabel alloc]init];
        _floorNameLabel.font = [UIFont systemFontOfSize:16.0];
    }
    return _floorNameLabel;
}

-(UILabel *)buildingNameLabel
{
    if (!_buildingNameLabel) {
        _buildingNameLabel = [[UILabel alloc]init];
        _buildingNameLabel.font = [UIFont systemFontOfSize:15.0];
    }
    return _buildingNameLabel;
}

//-(UILabel *)roomTotalLabel
//{
//    if (!_roomTotalLabel) {
//        _roomTotalLabel = [[UILabel alloc]init];
//        _roomTotalLabel.font = [UIFont systemFontOfSize:15.0];
//    }
//    return  _roomTotalLabel;
//}

-(UIImageView *)floorImgView
{
    if (!_floorImgView) {
        _floorImgView = [[UIImageView alloc]init];
        _floorImgView.image = [UIImage imageNamed:@"assignTimeImage"];
    }
    return _floorImgView;
}


#pragma mark -- roomNo自适应长度
-(CGFloat)calculateWidth:(CGFloat)width string:(NSString *)str Font:(CGFloat)font
{
    CGSize size =CGSizeMake(width,20);
    
    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:font],NSFontAttributeName,nil];
    
    //ios7方法，获取文本需要的size，限制宽度
    
    CGSize  actualsize =[str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
    return actualsize.width;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
